<template>
  <div>
    <el-row>
      <el-col :span="16">
        <el-tag>线索ID：{{id}}</el-tag>
        <el-descriptions class="margin-top"  :column="3"  border>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-user"></i>
              创建时间
            </template>
            {{form.createTime}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-mobile-phone"></i>
              手机号
            </template>
            {{form.phone}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-location-outline"></i>
              渠道来源
            </template>
            苏州市
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-tickets"></i>
              线索归属
            </template>
            {{form.owner}}
            <!--        <el-tag size="small">学校</el-tag>-->
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-office-building"></i>
              活动信息
            </template>
            江苏省苏州市吴中区吴中大道 1188 号
          </el-descriptions-item>
        </el-descriptions>
        <el-button type="danger" @click="handleFalseClue" v-if="(form.status == 1||form.status == 2) && form.falseCount < 3">伪线索</el-button>
        <el-button type="success" v-if="form.status == 1||form.status == 2" @click="handleTransFrom">转商机</el-button>
        <el-divider></el-divider>

        <el-form ref="form" :model="form" :disabled="disabled" :rules="rules" label-width="80px">
          <el-form-item label="客户姓名" prop="name">
            <el-input v-model="form.name" type="textarea" placeholder="请输入客户姓名" />
          </el-form-item>
          <el-form-item label="性别" prop="sex">
            <el-select v-model="form.sex"
                       placeholder="请输入性别"
                       clearable >
              <el-option
                v-for="dict in dict.type.sys_user_sex"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item type="number" label="年龄" prop="age">
            <el-input v-model="form.age" placeholder="请输入年龄" />
          </el-form-item>
          <el-form-item label="微信号" prop="weixin">
            <el-input v-model="form.weixin" placeholder="请输入微信号" />
          </el-form-item>
          <el-form-item label="QQ号" prop="qq">
            <el-input v-model="form.qq"  placeholder="请输入QQ号" />
          </el-form-item>
          <el-form-item label="意向等级" prop="level">
            <el-select v-model="form.level"
                       placeholder="请输入意向等级"
                       clearable >
              <el-option
                v-for="dict in dict.type.clues_level"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="意向学科" prop="subject">
            <el-select v-model="form.subject"
                       placeholder="请输入意向学科"
                       clearable >
              <el-option
                v-for="dict in dict.type.course_subject"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="跟进记录" prop="record">
            <el-input v-model="form.record"  placeholder="请输入跟进记录" />
          </el-form-item>
          <el-form-item label="下次跟进时间" prop="nextTime">
            <el-date-picker
              v-model="form.nextTime"
              type="datetime"
              placeholder="下次跟进时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm"  v-if="(form.status == 1||form.status == 2) && !disabled">保存</el-button>
            <el-button>重置</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="8">
        <track-list :id="id" :key="trackListKey" :search="'线索'" ref="trackaa"></track-list>
      </el-col>
    </el-row>
    <false-clue ref="falseClueDialog" @success="handleSuceess"></false-clue>
  </div>
</template>

<script>
import {getClue} from "@/api/crm/clue";
import { addClueTrack ,tranform2Business } from "@/api/crm/clueTrack";
import TrackList from "@/views/crm/clue/component/track-list.vue";
import FalseClue from "@/views/crm/clue/component/false-clue.vue";

export default {
  name: "teack-index",
  components: {TrackList,FalseClue},
  props:{
    clueId:{
      type:[String,Number],
    },
    view:{
      type:Boolean,
    }
  },
  dicts:['sys_user_sex','clues_level','course_subject'],
  data(){
    return{
      id: this.clueId,
      form:{},
      rules: {},
      trackListKey:0,
      disabled:false,
    }
  },
  watch:{
    clueId(newValue,oldalue){
      this.id = newValue;
      this.getList()
    },
    view:{
      handler:function (newValue,oldValue){
        this.disabled = newValue
      },
      immediate:true
    }
  },
  created() {
    this.getList();
  },
  methods:{
    getList(){
      getClue(this.id).then(resp => {
        this.form = resp.data;
      })
      this.trackListKey++;
    },
    submitForm(){
      addClueTrack(this.form).then(resp => {
        this.$message.success('成功')
        this.$refs.trackaa.id = this.id;
        this.getList()
        this.$refs.trackaa.getList()
        this.$emit('seccess')
      })
    },
    handleFalseClue(){
      this.$refs.falseClueDialog.open = true
      this.$refs.falseClueDialog.id = this.id
      this.$refs.falseClueDialog.resetForm();
    },
    handleSuceess(){
      this.$message.success('操作成功')
      this.getList()
      this.$emit('success')
    },
    handleTransFrom(){
      this.$msgbox.confirm(`确定转换线索${this.id}到商机吗？`).then(() =>{
        console.log(this.id);
        tranform2Business({id: this.id,record:'转商机'}).then(resp =>{
          this.handleSuceess();
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
